

const requestMode = require('../../../js/requestsMode.js');
const constants = require('../../../js/constants.js');
const session = require('../../../js/session.js');
const  Tools = require('../../../js/Tools.js');
Page({
    data:{
        placeOrderTime:"",
        sendTime:'',
        orderStatus:2,
        orderNumber:"",
        consignee:'',
        consigneePhone:'',
        GetAddress:'',
        OrderImg:'../../../images/wdl.png',
        orderName:"",
        orderPrice:'',
        senPrice:'',
        allPrice:'',
        yourOrderNumber:1
    },
    ////界面出现的时候回调
    onLoad : function (orderData) {
        // console.log("requestGetOrderId",orderData.order_id);
        let that = this;
        let order_id = orderData.order_id;
        requestMode.sendRequest("order/detail",'POST',{order_id:order_id},{sKey:session.get('sKey')}).then(function(success){
            let requestSuccessCode = success.data.code,requestSuccessData = success.data.data;
            if(requestSuccessCode == 200){
                that.setData({
                    goods_info_list : requestSuccessData.goods_info.list,
                    goodsCount :  requestSuccessData.goods_info.total,
                    goods_give_info : requestSuccessData.goods_give_info,
                    coupon_value : requestSuccessData.coupon_value,
                    goods_give_info_list : requestSuccessData.goods_give_info.list,
                    orderPrice : requestSuccessData.total_fee,
                    senPrice : requestSuccessData.freight,
                    allPrice :  (parseFloat(requestSuccessData.real_pay)+parseFloat(requestSuccessData.freight)).toFixed(2),
                    full_cut_value : requestSuccessData.full_cut_value,
                    order_id : order_id,
                    order_status : requestSuccessData.status,
                    address_info : requestSuccessData.address_info,
                    order_number : requestSuccessData.order_number,
                    pay_type : requestSuccessData.pay_type
                });
                Tools.showSuccessInfoToast("提交订单成功")
            }else{
                Tools.showErrorToast(success.data.message)
            }
        }, function (fail) {
            Tools.showWrongNetWorkToast();
        });
    },
    seeDetailedShopping:function(){
        wx.redirectTo({
            url:'../seeMinesOrder/seeMinesOrder?type=1'
        })
    },
    cancelOrder: function () {
        let that = this;
        wx.showModal({
            content: '您确定取消此订单吗？',
            success: function (res) {
                if (res.confirm) {
                    Tools.showLoaddingDefault();
                    requestMode.sendRequest('order/remove','POST',{order_id:that.data.order_id},{sKey:session.get('sKey')}).then(function (removeOrderSuccess) {
                        let getCode = removeOrderSuccess.data.code;
                        if(getCode == 200){
                            Tools.showSuccessInfoToast('操作成功');
                            Tools.hideLoaddingToast();
                            wx.reLaunch({
                                url:'../../type/type'
                            });
                        }else{
                            Tools.showErrorToast(removeOrderSuccess.data.message);
                        }
                    },function(){
                        Tools.showWrongNetWorkToast();
                    })
                }
            }
        });
    }
});